package com.balabala.gym_user.controller.sms;

import cn.hutool.core.util.PhoneUtil;
import com.balabala.exception.CustomerException;
import com.balabala.gym_enum.ExceptionEnum;
import com.balabala.gym_enum.ResultEnum;
import com.balabala.gym_user.service.SmsService;
import com.balabala.gym_user.service.UserService;
import com.balabala.result.Result;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author 何涛
 * @Date: 2023/04/30/ 13:33
 * @description 短信接口
 */
@RestController
@RequestMapping("/sms")
@Slf4j
@CrossOrigin
@Api(tags = "短信相关接口")
public class SmsController {
    @Autowired
    SmsService smsService;
    @GetMapping("/sendSmsCode")
    public Result sendSmsCode(String phone)
    {
        //校验电话号码是否合法
        if(!PhoneUtil.isPhone(phone)) {
            throw new CustomerException(ExceptionEnum.PHONE_ILLEGAL);
        }
        log.info("phone：{}请求发送验证码",phone);
        smsService.sendSmsCode(phone);
        return Result.ok(ResultEnum.SMS_CODE_SUCCESS);
    }
}
